public class TestBinaryTree {
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val=val;
        }
    }

    public TreeNode createTree() {
        TreeNode A=new TreeNode('A');
        TreeNode B=new TreeNode('B');
        TreeNode C=new TreeNode('C');
        TreeNode D=new TreeNode('D');
        TreeNode E=new TreeNode('E');
        TreeNode F=new TreeNode('F');
        TreeNode G=new TreeNode('G');
        TreeNode H=new TreeNode('H');
        A.left=B;
        A.right=C;
        B.left=D;
        B.right=E;
        E.right=H;
        C.left=F;
        C.right=G;
        return A;
    }

    //前序遍历 根    左   右
    void preOrder(TreeNode root) {
        if(root==null) {
            return;
        }
        System.out.print(root.val+" ");
        //递归遍历左子树
        preOrder(root.left);
        //递归遍历右子树
        preOrder(root.right);
    }

    // 中序遍历
    void inOrder(TreeNode root) {
        if(root==null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }

    // 后序遍历
    void postOrder(TreeNode root) {
        if(root==null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val+" ");
    }

    // 获取树中节点的个数
    public int size(TreeNode root) {
        if(root==null) return 0;
        int ret=size(root.left)+size(root.right)+1;
        return ret;
    }

    public static int nodeSize;
    public void size2(TreeNode root) {
        if(root==null) return;
        nodeSize++;
        size2(root.left);
        size2(root.right);
    }

    // 获取叶子节点的个数
    int getLeafNodeCount(TreeNode root) {
        if(root==null) return 0;
        if(root.left==null && root.right==null) {
            return 1;
        }
        return getLeafNodeCount(root.left)+
                getLeafNodeCount(root.right);
    }

    public int leafNodeSize;
    void getLeafNodeCount2(TreeNode root) {
        if(root==null) return;
        if(root.left==null && root.right==null) {
            leafNodeSize++;
        }
        getLeafNodeCount2(root.left);
        getLeafNodeCount2(root.right);
    }
}
